<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <link rel="stylesheet" href="css/amazeui.min.css" />
    <link rel="stylesheet" href="css/index_2.css" />
    <title>忘记支付密码</title>
</head>

<body>
    <!--头部-->
    <header class="am-u">
        <div class="am-u-sm-12 head_nav">
            <div class="am-u-sm-2 am-vertical-align">
                <a href="Paymentpassword.html">
                    <img src="img/return@2x.png" class="am-vertical-align-middle" alt="" />
                </a>
            </div>
            <div class="am-u-sm-8 head_text">
                忘记支付密码
            </div>
            <div class="am-u-sm-2">

            </div>
        </div>
    </header>
    <!--输入框-->
    <div class="am-u">
        <div class="am-u-sm-12">

            <div class="am-u-sm-12 verification">
                <div class="am-u-sm-7 am-vertical-align verification_code" style="border:1px solid #ddd;">
                    <input type="text" class="am-vertical-align-middle" id="code" placeholder="输入验证码" />
                </div>
                <div class="am-u-sm-5" style="padding:0;">
                    <button type="button" class="verification_btn" style="padding:1px 0;">发送验证码</button>
                </div>
            </div>
            <div class="input_box am-vertical-align" style="clear:both;">
                <input type="password" class="am-vertical-align-middle" id="new_pay_pwd" placeholder="输入新的支付密码" />
            </div>
            <div class="input_box am-vertical-align">
                <input type="password" class="am-vertical-align-middle" id="new_pay_pwd1" placeholder="重新输入支付密码" />
            </div>

            <div style="padding:0 7.5px;">
                <button type="button" class="complete_btn">重置支付密码</button>
            </div>
        </div>
    </div>
    <script src="js/jquery-1.11.3.js"></script>
    <script>
        var token1 = sessionStorage['token'];
        $(".verification_btn").click(function () {
            var d = {};
            d.method = "Phonecode|send";
            d.type = "forget_pay_pwd";
            d.token = token1;
            var url = "http://www.rice.com/app/api/h5_access";
            $.ajax({
                type: "post",
                url: url,
                data: d,
                dataType: "json",
                success: function (result) {
                    if (result.status == "1") {
                        alert(result.message);
                        var time = 180;
                        $('.verification_btn').html(time + "秒后重发").attr('disabled', true);
                        setInterval(function () {
                            time--;
                            if (time === 0) {
                                $('.verification_btn').html("发送验证码").attr('disabled', false);
                            } else if (time > 0) {
                                $('.verification_btn').html(time + "秒后重发").attr('disabled',
                                    true);
                            }

                        }, 1000);
                    } else if (result.status == "2") {
                        alert(result.message);
                        location.href = "login.html";
                    } else {
                        alert(result.message);
                    }
                }

            })
        });
        $(".complete_btn").on("click", function () {
            var code1 = $("#code").val();
            var new_pay_pwd2 = $("#new_pay_pwd").val();
            var new_pay_pwd3 = $("#new_pay_pwd1").val();
            if (code1 == "" || code1 == null) {
                alert("请输入验证码");
                return false;
            }
            if (new_pay_pwd2 == "" || new_pay_pwd2 == null) {
                alert("请输入支付密码");
                return false;
            }
            if (new_pay_pwd2 != new_pay_pwd3) {
                alert("两次输入的支付密码不一致");
                return false;
            }
            var c = {};
            c.method = "User|forget_pay_pwd";
            c.token = token1;
            c.code = code1;
            c.new_pay_pwd = new_pay_pwd2;
            var url = "http://www.rice.com/app/api/h5_access";
            $.ajax({
                type: "post",
                url: url,
                data: c,
                dataType: "json",
                success: function (result) {
                    if (result.status == "1") {
                        alert(result.message);
                        location.href = "setting.html";
                    } else if (result.status == "2") {
                        alert(result.message);
                        location.href = "login.html";
                    } else {
                        alert(result.message);
                    }
                }

            })
        })
    </script>
</body>

</html>